

public class SportStacker {
  private String name;
  private int    numTimesRecorded;
  double[]       times;
  
  // Constructor
  public SportStacker(String newName, int numTimes) {
    name = newName;
    numTimesRecorded = 0;
    times = new double[numTimes];
  }
  
  // toString
  @Override public String toString() {
    String record = "Sport Stacker name: " + name + "\n";
    record += "Number of times recorded " + numTimesRecorded + "\n";
    record += "Times: ";
    for (int index = 0; index < numTimesRecorded; index++)
      record += times[index] + " ";
    return record;
  }
  
  // increase array size
  private void increaseSize() {
    double[] temp = new double[numTimesRecorded + 1];
    for (int Times = 0; Times < numTimesRecorded; Times++)
      temp[Times] = times[Times];
    times = temp;
  }
  
  // addtime
  void addTime(double time) {
    if (numTimesRecorded == times.length)
      increaseSize();
    times[numTimesRecorded] = time;
    numTimesRecorded++;
  }
  
  // remove slowest
  void removeSlowestTime() {
    int max = 0;
    for (int temp = 0; temp < times.length; temp++) {
      if (times[temp] > times[max])
        max = temp;
    }
    times[max] = 0.0;
    for (int i = max; i < times.length - 1; i++) {
      times[i] = times[i + 1];
    }
    times[times.length - 1] = 0;
    numTimesRecorded--;
  }

  // fastest time
  double computeFastestTime() {
    int max = 0;
    for (int temp = 0; temp < this.numTimesRecorded; temp++) {
      if (times[temp] < times[max])
        max = temp;
    }
    return times[max];
  }
  
  double computeAvgerageTime() {
    double total = 0;
    for (int temp = 0; temp < this.numTimesRecorded; temp++)
      total = (total + times[temp]);
    return total / numTimesRecorded;
  }
}
